// components/edu-com/edu-class.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  properties: {

  },
  lifetimes:{
    attached(){
      let datelist = this.data.datelist;
      let Cloud = app.Cloud;
      Cloud.getKbcxAzc(app.globalData.xh).then(res => {
        console.log(res)
        let classlist = res.result;
        classlist.forEach(function (ele, index) {
          let day = datelist[parseInt(ele.kcsj[0] - 1)];
          ele.day = day;
          ele.start = parseInt(ele.kcsj.substring(1, 3));
          ele.end = parseInt(ele.kcsj.substring(3, 5));
        })
        this.setData({
          classList: classlist
        }, () => {
          this.getShowList();
        })
      })
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    datelist: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    TabCur: 0,
    scrollLeft: 0,
    classList: [],
    showList: [],
    showit:false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    getShowList(day) {
      var that = this;
     // console.log(day)
      let today = '周一';
      if (day == undefined) {
        var now = new Date();
        var day = now.getDay();
        let index = (day+6)%7;
        //index=3
        today = this.data.datelist[index];
        this.setData({
          TabCur:index
        })
      }else{
        today = day;
      }
      let carr = this.data.classList;
      let tarr = [];
      for(var i=0;i<carr.length;i++){
        //console.log(carr[i].day)
        if(carr[i].day==today){
          tarr.push(carr[i])
        }
      }
      console.log(tarr)
      that.setData({
        showList:tarr,
        showit:true
      },()=>{
        this.triggerEvent('listener','今日课表')
      })
    },
  }
})
